package com.shop.zzh.component;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.shop.zzh.mbg.model.UserLog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

/**
 * @program: shop
 * @description: 消息队列消费者
 * @author: zhuzh
 * @create: 2019-11-21 18:10
 **/
@Component
public class ReceiveMessage {

	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private ObjectMapper objectMapper;


	@RabbitListener(queues = "${log.user.queue.name}",containerFactory = "singleListenerContainer")
	public void process(@Payload byte[] message) {
		try{
			UserLog userLog = objectMapper.readValue(message,UserLog.class);
			logger.info("接收处理队列A当中的消息： " + userLog);
		}catch (Exception e){
			e.printStackTrace();
		}
	}
}
